package com.tg.app.helper;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.tange.base.toolkit.StringUtils;
import com.tg.app.R;
import com.tg.appcommon.android.ResourcesUtil;
import com.tg.data.helper.SoundHelper;
import com.tg.data.http.entity.DeviceBellBean;

public class AlertSoundHelper extends SoundHelper {
    @NonNull
    public static AlertSoundHelper getInstance() {
        return AlertSoundHelper.SingletonHolder.sInstance;
    }

    AlertSoundHelper() {
    }

    private static class SingletonHolder {
        static final AlertSoundHelper sInstance = new AlertSoundHelper();
    }

    @Override
    public boolean deleteNoExistFile(@NonNull String idAlarmTone) {
        if (mExist) {
            return false;
        }

        if (mCloudList.size() > 0) {
            if (!StringUtils.isEmpty(mIdAlarmTone) && mIdAlarmTone.equals(idAlarmTone)) {
                mList.remove(mCloudList.get(mCloudList.size() - 1));
                mCloudList.remove(mCloudList.get(mCloudList.size() - 1));
            }
        }

        mExist = true;
        return true;
    }


    @Override
    public DeviceBellBean getCustomDeviceBellBean() {
        for (DeviceBellBean deviceBellBean : mList) {
            if (deviceBellBean.getId().equals(mSelectAlarmTone)) {
                return deviceBellBean;
            }
        }
        return null;
    }

    @Override
    public String getShowText() {
        if (TextUtils.isEmpty(mSelectAlarmTone)) {
            return ResourcesUtil.getString(R.string.alarm_sound_default);
        }
        for (DeviceBellBean deviceBellBean : mCloudList) {
            if (mSelectAlarmTone.equals(deviceBellBean.getId())) {
                return deviceBellBean.getDescription();
            }
        }
        for (DeviceBellBean deviceBellBean : mList) {
            if (mSelectAlarmTone.equals(deviceBellBean.getId())) {
                return deviceBellBean.getDescription();
            }
        }
        return ResourcesUtil.getString(R.string.txt_current_voice);
    }

    @Override
    public boolean exist() {
        if (TextUtils.isEmpty(mIdAlarmTone)) {
            return true;
        }
        for (DeviceBellBean deviceBellBean : mCloudList) {
            if (mIdAlarmTone.equals(deviceBellBean.getId())) {
                return true;
            }
        }
        for (DeviceBellBean deviceBellBean : mList) {
            if (mIdAlarmTone.equals(deviceBellBean.getId())) {
                return true;
            }
        }
        return false;
    }

}
